package com.summary.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.summary.domain.Clocking;
import com.summary.domain.vo.UserVO;
import com.summary.service.IClockingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 请假业务Controller
 *
 * @author NightWalk
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/clocking")
public class ClockingController extends BaseController {
    @Resource
    private IClockingService clockingService;

    /**
     * 查询请假业务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Clocking clocking) {
        //startPage();
        List<UserVO> list = clockingService.selectClockingList(clocking);
        return getDataTable(list);
    }

    /**
     * 根据clockingId删除记录
     *
     * @param clockingId
     * @return
     */
    @DeleteMapping("/delete")
    public AjaxResult delete(Long clockingId) {
        return toAjax(clockingService.deleteClockingByNickName(clockingId));
    }

    /**
     * 修改请假的状态
     *
     * @param clocking
     * @return
     */
    @PutMapping("/update")
    public AjaxResult update(Clocking clocking) {
        return toAjax(clockingService.updateClockingType(clocking));
    }

    /**
     * 新增请假业务
     */

    @PostMapping("/insert")
    public AjaxResult add(@RequestBody Clocking clocking) {

        return toAjax(clockingService.insertClocking(clocking));
    }

    /**
     * 根据clockingId查询请假记录
     *
     * @param clockingId
     * @return
     */
    @GetMapping("/oneClocking")
    public AjaxResult selectOne(Long clockingId) {
        return success(clockingService.selectOneClockingByClockingId(clockingId));
    }


    @GetMapping("/days")
    public AjaxResult getDayNumber(int month){
        return success((clockingService.getDayNumber(month)));
    }
}
